package engine.display.newAttack
{
	import engine.scene.SceneChangeManager;
	
	import flash.display.MovieClip;
	import flash.geom.Point;
	
	import newx.StageInfo;
	import newx.com.ResManager;

	/**
	 *	战斗场景控制 
	 * @author lw
	 * 
	 */
	public class AttackSceneLogic
	{
		private static	 var _self	:	AttackSceneLogic;
		
		private var _space : MovieClip;
		
		public static function getInstance():AttackSceneLogic
		{
			if ( _self == null )
			{
				_self = new AttackSceneLogic();
			}
			return _self;
		}
		
		public function AttackSceneLogic():void
		{
		}
		
		public function changeAttackSceneScale( scene : AttackSceneView, scale : Number ):void
		{
			if( null == _space )
			{
				_space = ResManager.newResClass( "CustomControl_057" ) as MovieClip;
			}
			
			scene.scaleX = scene.scaleY = scale;
			
			var point : Point = getCenterPoint();
			
			scene.x = point.x - scene.width * .5;
			scene.y = point.y - scene.height * .5;
			StageInfo.sceneSpace.mouseChildren = StageInfo.sceneSpace.mouseEnabled = false;
			StageInfo.uiSpace.mouseChildren = StageInfo.uiSpace.mouseEnabled = false;
			
			_space.x = scene.x - 6;
			_space.y = scene.y;
			_space.width = scene.width;
			_space.height = scene.height - 5;
			
			StageInfo.attackSpace.addChild( _space );
		}
		
		public function getCenterPoint():Point
		{
			return 	 StageInfo.attackSpace.globalToLocal( new Point( StageInfo.stage.stageWidth * .5, StageInfo.stage.stageHeight * .5 ) );
		}
		
		public function resetAttackSceneScale( scene : AttackSceneView ):void
		{
			scene.scaleX = scene.scaleY = 1;
			
			scene.x = SceneChangeManager.attackSceneViewX;
			scene.y = SceneChangeManager.attackSceneViewY;
			
			StageInfo.sceneSpace.mouseChildren = StageInfo.sceneSpace.mouseEnabled = true;
			StageInfo.uiSpace.mouseChildren = StageInfo.uiSpace.mouseEnabled = true;
			
			if( null != _space && null != _space.parent )
			{
				_space.parent.removeChild( _space );
			}
		}
	}
}